var license = new Vue({
    el: "#license",
    data() {
        return {
            loading: false,
            applyData: {
                applyCode: null,
                authorizeCode: null,
                monthNum: null,
            },
            rules: {
                applyCode: [
                    {required: true, message: '请填写申请码!', trigger: 'blur'}
                ],
                monthNum: [
                    {required: true, message: '请填写授权时长!', trigger: 'blur'}
                ]
            }

        };
    },
    created() {

    },
    mounted() {

    },
    computed: {
    },
    methods: {
        // getApplyCode() {
        //   $.ajax({
        //       url: '/getApplyCode',
        //       dataType: "json",
        //       type: "GET",
        //       success: res => {
        //           this.applyData.applyCode = res.license;
        //       },
        //       error: err => {
        //           console.log(err)
        //       }
        //   })
        // },

        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.loading = true;
                    $.ajax({
                        url: '/getAuthorizeCode',
                        dataType: "json",
                        data: {
                            applyCode: this.applyData.applyCode,
                            monthNum: this.applyData.monthNum,
                        },
                        type: "post",
                        success: res => {
                            if(res.success) {
                                this.applyData.authorizeCode = res.authorizeCode;
                            } else {
                                alert(res.msg)
                            }
                            this.loading = false;
                        },
                        error: err => {
                            console.log(err)
                            this.loading = false;
                        }
                    })
                }
            })


        }

    },
});